# -*- coding = utf-8 -*-
# @Time    : 2025/3/30 上午10:51
# @Author  : yqk
# @File    : 设置元素加载和等待策略.py
# @Software: PyCharm
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

service = Service(r'D:\python-code\chromedriver-win64\chromedriver.exe')

opt = Options()
opt.add_argument('--disable-blink-features=AutomationControlled')
opt.page_load_strategy = 'eager' # 默认是normal，normal：等待页面完全加载完成，eager：等待页面基本加载完成，interactive：等待页面基本加载完成，但是不加载图片，css，js等资源，这个性能最好，但是页面加载速度会慢一点
browser = webdriver.Chrome(service=service, options=opt)
browser.implicitly_wait(5)
url = 'https://www.lagou.com/'

browser.get(url)
# city_elements = browser.find_element(By.XPATH, '//*[@id="lg_tbar"]/div[1]/ul/li[1]')
# city_elements.click()
# time.sleep(3)

search = browser.find_element(By.XPATH, '//*[@id="search_input"]')
search.send_keys('Python爬虫工程师', Keys.ENTER)
input('回车退出')
